package com.ruoyi.slope.ai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.ai.domain.SlopeAiModelLibrary;
import com.ruoyi.slope.ai.service.ISlopeAiModelLibraryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * AI模型/算法库Controller
 * 
 * @author ruoyi
 * @date 2025-09-05
 */
@RestController
@RequestMapping("/ai/modelLibrary")
public class SlopeAiModelLibraryController extends BaseController
{
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeAiModelLibraryService slopeAiModelLibraryService;

    /**
     * 查询AI模型/算法库列表
     */
    @PreAuthorize("@ss.hasPermi('ai:modelLibrary:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeAiModelLibrary slopeAiModelLibrary)
    {
        startPage();
        List<SlopeAiModelLibrary> list = slopeAiModelLibraryService.selectSlopeAiModelLibraryList(slopeAiModelLibrary);
        return getDataTable(list);
    }

    /**
     * 导出AI模型/算法库列表
     */
    @PreAuthorize("@ss.hasPermi('ai:modelLibrary:export')")
    @Log(title = "AI模型/算法库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeAiModelLibrary slopeAiModelLibrary)
    {
        List<SlopeAiModelLibrary> list = slopeAiModelLibraryService.selectSlopeAiModelLibraryList(slopeAiModelLibrary);
        ExcelUtil<SlopeAiModelLibrary> util = new ExcelUtil<SlopeAiModelLibrary>(SlopeAiModelLibrary.class);
        String path = util.exportExcel(response, list, "AI模型/算法库数据");
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取AI模型/算法库详细信息
     */
    @PreAuthorize("@ss.hasPermi('ai:modelLibrary:query')")
    @GetMapping(value = "/{modelId}")
    public AjaxResult getInfo(@PathVariable("modelId") String modelId)
    {
        return success(slopeAiModelLibraryService.selectSlopeAiModelLibraryByModelId(modelId));
    }

    /**
     * 新增AI模型/算法库
     */
    @PreAuthorize("@ss.hasPermi('ai:modelLibrary:add')")
    @Log(title = "AI模型/算法库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeAiModelLibrary slopeAiModelLibrary)
    {
        return toAjax(slopeAiModelLibraryService.insertSlopeAiModelLibrary(slopeAiModelLibrary));
    }

    /**
     * 修改AI模型/算法库
     */
    @PreAuthorize("@ss.hasPermi('ai:modelLibrary:edit')")
    @Log(title = "AI模型/算法库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeAiModelLibrary slopeAiModelLibrary)
    {
        return toAjax(slopeAiModelLibraryService.updateSlopeAiModelLibrary(slopeAiModelLibrary));
    }

    /**
     * 删除AI模型/算法库
     */
    @PreAuthorize("@ss.hasPermi('ai:modelLibrary:remove')")
    @Log(title = "AI模型/算法库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{modelIds}")
    public AjaxResult remove(@PathVariable String[] modelIds)
    {
        return toAjax(slopeAiModelLibraryService.deleteSlopeAiModelLibraryByModelIds(modelIds));
    }
}
